package org.learn.test;

public class HomeWork09 {
    public static void main(String[] args) {
        A01 a01 = new A01();
        double[] arr = {1,2,3,4,5,56,6,7,};
        System.out.println("arr的最大值是==" + a01.max(arr));

        //
        A02 a02 = new A02();
        String[] arr1 = {"jack","tom","look"};
        int index = a02.find("tom",arr1);
        System.out.println("查找到的index=" + index);
    }
}
class A01 {
    public double max(double[] arr){
        //保证arr的长度有效
        if(arr.length > 0) {
            double max = arr[0];
            for (int i = 0; i < arr.length; i++) {
                if (max > arr[i]) {
                } else {
                    max = arr[i];
                }
            }
            return max;
        }else{
            return -1;
        }
    }

}
class A02 {
    public int find(String s,String[] arr){
        for(int i = 0;i < arr.length;i++){
            if(s.equals(arr[i])){
                return i;
            }
        }
        //如果没有找到就返回-1
        return -1;
    }
}